home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 27
/
Commodore_Free_Issue_27_2009_Commodore_Computer_Club.d64
/
iv owen
< prev
next >
Wrap
Text File
|
2023-02-26
|
18KB
|
615 lines
..
Interview with Simon Owen
Sinclair Spectrum Vic 20
emulator creator
http://simonowen.com/
spectrum/vic20emu/
COMMODORE FREE
Please introduce yourself to our
readers
SIMON OWEN
I'm Simon Owen from Nottingham in the
UK. I'm 36 & work as a software
developer, writing mainly Windows
software for multi-function
(fax/print/scan) devices. In my spare
time I work on a variety of retro-
themed coding projects. Most of them
involve the Spectrum, SAM Coupe or
floppy disks, but I'll dabble in a
bit of anything I find interesting.
CF. Can you tell our readers a little
about your first computing moments?
SO. I wrote my very first (BASIC)
program on a computer my Dad borrowed
from work, which was a large beige
machine with green screen display &
twin 8" floppy drives. My first
proper home computer was a Jupiter
Ace, back at the time when many
people had VIC-20s or ZX81s. The Ace
used Forth rather than BASIC as its
built-in language, which was a bit
mind-bending for me as a 10 year old!
I finally joined the mainstream a
couple of years later, with a 48K
Spectrum+. It was largely used for
playing games, but after getting
Hisoft DevPac for a birthday present
I spent more & more time programming.
From there I moved to the Spectrum
128+ in 1986, & the SAM Coupe when it
was released in 1989.
CF. Are you a C= user?
SO. Only on the 16-bit side, really
I've got A500 & A1200 machines. The
A500 was originally so I could work
on Uni projects at home, but I soon
got sucked into demos & gaming. The
A1200 is still very much alive today,
thanks to an accelerator board &
bootable Compact Flash card.
I'd still very much like a C64,
though I'm not sure I could go back
to loading from tapes. I'll
definitely get one if I can find a
ready-made CF or Ethernet solution
for loading software. I'm aware of
the IDE64 project, but like most
retro hardware projects it expects
everyone to assemble their own, &
unfortunately I'm a fire hazard with
a soldering iron!
I also have a SID interface board for
my SAM Coupe, as I'm a fan of C64
music. The 6502 core used by the VIC
emulator was actually written for my
SAM HardSID player, which can play
most SID tunes through the SID board.
CF. Why design a VIC-20 emulator for
the ZX Spectrum? Are you stuck for
things to do?
SO. Mainly because I like a technical
challenge! I never really pay too
much attention to how useful the
final program will be, & if just one
other person appreciates what's been
achieved then I'm happy. The VIC-20
emulator is my third 6502-based
emulator, after Orao & Apple 1. It
was definitely a step up in
difficulty, but the hardware
requirements didn't seem too extreme
to be worth a go.
CF. The speed of the emulation must
have been a problem. Were there any
specific tricks you had to use to
obtain better performance?
SO. I try not to worry too much about
the final running speed, as I know a
standard Spectrum will never reach
100%. Even so, the 6502 core has been
highly optimised over the years, & I
feel there's little room for further
gains.
The emulator does use a few tricks to
maximise performance. The version of
the 6502 core used by the VIC
emulator traps only memory writes, so
reads are fast & direct. To support
I/O reads from devices such as the
keyboard, the write handlers prepare
the memory state for the reads. For
the keyboard that means writes to the
row selection at $9120 will prepare
the keyboard state result at
$9121/$912f.
Another optimisation is to use a
large look-up table to map from VIC
to Spectrum display addresses, to
minimise the calculations during
display writes. This table must be
rebuilt if the number of VIC
rows/columns changes, but that
doesn't happen very often so it's
still well worthwhile.
Perhaps the biggest outstanding
performance issue is the VIC ROM
keyboard scanning performed by the
interrupt handler. If a quick test
shows that no key is pressed the
scanner exits early. Otherwise it
continues to perform a full keyboard
matrix scan, which eats a significant
portion of the CPU time each frame as
long as a key remains pressed. That's
a problem for games that use keys
instead of joystick for control.
CF. I know the Spectrum had a faster
processor than the VIC but the
graphics & sound must have caused
problems when writing the emulator?
SO. The VIC high-resolution mode
actually maps through fairly well,
with the Spectrum using a similar
attribute system for each character.
The Spectrum 128 sound chip
(AY-3-8912) supports 3 tone channels
plus a noise channel, which also
matched the VIC capabilities.
Unfortunately, the output from the AY
noise generator is very limited, so
the roaring firing noise in
GridRunner becomes an irritating
background hiss on the Spectrum
version.
On the issue of processor speed, the
Z80 typically requires more CPU
cycles to do the same work, so the
speed is much closer than you'd
imagine. A simple example is LDA #0
(2 cycles @1MHz) & LD A,0 (7 cycles
@3.5MHz), which both take around the
same amount of real time to execute.
You can see bigger differences if you
look at the strengths of each
processor. The fastest Z80
instruction (4 cycles) is twice as
fast on the Spectrum (3.5Hz) as the
fastest 6502 instruction (2 cycles)
on the VIC (1MHz). There are more
general purpose Z80 registers, which
provide faster working space than
main memory. The 16-bit register
pairs also give easy access to any
location in the 64K address space, as
well as 16-bit arithmetic.
On the other hand, a typical 6502
program averages around 2.5 cycles
per instruction, which is only just
above the minimum instruction time of
2 cycles. I also found that many
tasks typically require fewer 6502
instructions compared to the Z80.
Zero page addressing also more than
makes up for the lack of working
registers too, & you're less likely
to run out of them even with the most
complex tasks.
CF. Colour clashing on the Spectrum
was a problem. Has this caused
issues with emulation?
SO. The VIC's high-resolution mode is
very similar to the Spectrum display,
so it wasn't really a problem. In
both cases each 8x8 pixel block has a
foreground & a background colour. The
VIC background colour is system-wide,
with 4 bits selecting from the
complete palette of 16 colours. 3
bits from the colour RAM select one
of 8 foreground colours for the 8x8
block. On the Spectrum each block has
a separate foreground & background
colour (3 bits for each), as well as
bright & flash bits. The bright bit
increase the intensity of both
foreground & background colours.
The emulator uses a table to map from
VIC to Spectrum colours; since not
all colours are available (orange is
crudely mapped to yellow). Since the
upper half of the VIC colours are
roughly bright versions of the lower
ones, bit 3 of the VIC background
colour is mapped to the Spectrum
bright bit. That does mean the
foreground becomes bright too, but
that doesn't make much difference
overall.
CF. Writing an emulator where do you
start? I presume there must have
been a lot of reading & internet
trawling for specifications about the
Vic's hardware?
SO. I'd done a little research before
I started, just to make sure it was
vaguely possible. I generally check
that there is enough room for my
emulator code in the same address
space, which requires around 4K for
the base 6502 emulator or 8K with a
faster instruction decode table. Next
is to make sure the display can be
suitably represented, even if some
features are missing. I also check
for any custom hardware that might be
needed to run typical programs.
I'd already written the 6502
emulator, so it didn't take long to
make some real progress. It only took
about an hour to place the VIC ROM
code at the appropriate memory
locations & have it boot to the
start-up screen. The only special
code I needed was to stop the VIC
memory test overwriting the CHARGEN
ROM at $8000. Once I made that
location appear as ROM, it finished
the RAM test & set RAMTOP, & then
continued to boot. At that point
there was nothing to see on the
screen, but peeking the VIC display
memory locations I could see it was
showing the number of free bytes. A
small addition to trap writes to
$900F also gave the expected cyan
border.
CF. I don't want to get into the my
computer was better than yours as our
readers will mainly be C= users,
although I do know of some Spectrum
readers. There is still a rivalry
between machines why do you think
this still exists?
SO. I think there will always be some
rivalry, but (except for a few vocal
individuals) it seems to be fairly
light-hearted nowadays. Almost
everyone I've spoken to seems to have
at least some appreciation of the
other machine. Perhaps not
surprisingly, most people seem to
prefer the one they grew up with.
Would it surprise you to learn that
in a World of Spectrum poll comparing
the Spectrum 128K & C64 sound chips,
67% of votes were for the SID? :-)
CF. SAM Coupe! Some readers may not
be familiar with this machine you
also have a Vic emulator for this
machine can you enlighten our readers
about the machine?
SO. I see the SAM as a spiritual
successor to the Spectrum, even
though it's no direct relation. It
features a 6MHz Z80B, 512K RAM (plus
up to 4MB externally), 128 colours,
high colour & hi-res modes, 6 channel
sound, & up to 2 built-in floppy
drives. SAM is backwards compatible
with 48K Spectrum software, but only
native titles make the most of the
extra hardware, of course. The SAM
versions of Lemmings & Prince of
Persia stand up well against the
Atari ST versions. Unfortunately,
SAM's release in 1989 was at a time
when 16-bit machines were starting to
become popular. The user base was
also too small for much big name
commercial interest, instead relying
on smaller companies, diskzines &
home-grown software.
The SAM version of the VIC emulator
makes use of extra hardware features.
The faster processor gives a welcome
boost to running speed, the original
VIC colour palette is fully
supported, & the SAA 1099 noise
generator sounds much more authentic.
With a Mayhem accelerator card for
SAM running at 28MHz you can even
have it running at original VIC
speed!
CF. I know about 2 different spectrum
models the 16 & 48k but I have heard
there were other models, does this
emulator run on all spectrums. Can
you enlighten us on a little spectrum
history?
SO. The 16K & 48K versions were both
released in 1982. The very earliest
software ran on the 16K machines, but
it wasn't long before 48K was the
minimum requirement. Fortunately,
there was a RAM add-on to boost 16K
machines up to 48K. The vast majority
of Spectrum titles were aimed at the
48K market. The Spectrum+ update in
1984 was little more than the
original board in a new case, with a
hard plastic keyboard replacing the
rubber one.
The Spectrum 128K was released in
1986, featuring extra memory & a 3
channel sound chip (AY-3-8912). Games
used the improved sound for menu or
background music, & additional in
game sound effects. Only a handful of
games were 128K only, with most just
using the extra space for the music
player, digitised speech, or
pre-loading game levels.
After Amstrad took over the Spectrum
128 was repackaged in a CPC-like case
with improved keyboard & built-in
cassette recorder, & released as the
Spectrum +2. The final release was
the Spectrum +3, which replaced the
cassette recorder with a 3" disk
drive, as used by other Amstrad
machines. To simplify production the
later +2 machines (known as the +2A)
used the same main boards as the +3,
with boot-time detection of the disk
drive to know how it should identify
itself.
The VIC-20 emulator uses the extra
capabilities of the +2A & +3 to page
RAM into the full 64K address space,
so no memory mapping is needed
between VIC & Spectrum addressing.
That does mean it won't run on the
original 48K or even the base 128K
model, but since most users will be
using a Spectrum emulator it's not a
problem.
There is a second VIC-20 emulator for
the Spectrum, written by Jimmy. It
uses his own 6502 core & does include
the memory mapping needed to run on
48K machines. That does mean a speed
penalty for each memory access, but
the emulator does still run
surprisingly well.
CF. How long did creating the
emulator take?
SO. Start to finish was 18 months,
but I only spent about 2-3 weeks of
evenings actually working on it. The
first evening was to confirm the ROMs
booted, & to get a sample game cart
booting. After that I left it alone
to think about how best to emulate
the display. I only picked it up
again recently to finish it off.
I originally believed that changes to
chargen RAM would be used by games
for character animation. That would
mean tracking the visible characters,
to know which needed updating when
the underlying character memory was
changed. To do that would require
multiple levels of tables, with a
speed hit for all display writes.
Before I'd got that straight in my
head I'd moved on to other projects.
The final emulator is actually much
simplified, ignoring the chargen
memory writing that (it turns out)
very few programs need. Display
writes are still trapped, but the
only work is to write the current
character representation to the
Spectrum display. The only
complications are when the chargen
pointer ($9005) or rows/columns
($9002-3) are changed, when the
entire display must be redrawn.
CF. How many people are involved with
creating the package?
SO. Just me for the coding, but I've
had input from a number of people.
Jimmy helped kick-start me into
finishing the emulator, & various
optimisation ideas we've discussed
have benefitted both our emulators.
Dr Beep also provided a great
opcode-decode speed-up, where the
opcode itself forms the low-byte of
the handler address, for around a 5%
speed boost.
CF. What comments from the Spectrum
world have you had?
SO. Actually not very much, with more
feedback from the C= world! Most of
the Spectrum interest has been in the
6502 core, rather than the emulator
itself. Perhaps the VIC-20 is a
little too unknown to the average
Spectrum user, compared to the C64.
CF. Do you have plans for a C64
emulator for the Spectrum or SAM
Coupe? I guess speed would be a
major stumbling block.
SO. The C64 would definitely be a lot
more challenging. It would probably
need the extra video capabilities of
the SAM Coupe to support the colours
& modes for games. The need for
memory paging would mean moving from
direct to slower mapped memory
accesses, & trapping zero-page paging
I/O would slow all zero-page writes a
little. Graphic sprites would
complicate the display updating too,
requiring twice the amount of drawing
when they're moved. I'm very tempted
to look at supporting the C64 so that
BASIC is usable & if that goes well
then maybe I'll enhance it further.
CF. With the emulator not running at
full speed are there any programs
that just refuse to run?
SO. The running speed isn't a problem
for most programs, as they're not
aware of how fast they're running.
Any awareness they have of elapsed
time can be adjusted as part of the
emulation, if required. The most
likely reason for non-working
programs will be incomplete
emulation. For instance, I make no
attempt to support the hardware
timers or scan line counters, so
anything relying on them will fail.
It may be possible to add some basic
support for them, but I've not needed
them yet.
CF. How accurate is the emulation?
SO. The CPU emulation is quite
accurate, supporting all the
officially documented instructions.
It's actually a 65C02 emulation,
which includes some page-wrapping
fixes & new instructions that were
missing from the original 6502. The
VIC chip is not fully emulated, but
I've added enough support for the
sample programs to run. The display
is also narrower that the original
machine, but I believe that's just
the way the VIC display is generated,
where the pixels are fatter.
CF. Do you intend to support C=
hardware to attach to the spectrum,
maybe a cartridge port?
SO. It's unlikely original carts will
ever be supported directly as it
would require special hardware to
connect them to a Spectrum. I would
still like to support dumps of game
carts, as used by VICE & other
emulators. Cart support isn't
completely straight-forward either,
as some will move the address of the
VIC display, & the emulator is
optimised for the normal addresses.
It also depends on the memory banks
provided by the cart, as space is
needed for the Spectrum display & the
emulator itself.
CF. Did you consciously remove some
VIC features so that the emulator
would run faster or be quicker to
produce?
SO. The biggest feature omission is
the high-colour mode, which will be
needed by most newer VIC-20 games.
Not supporting it doesn't always make
a big difference to appearance; it
just shows with fewer colours. The
flags in Blitzkrieg still look like
flags, but they're missing the proper
blue & white colouring. High-colour
mode would only be possible with the
SAM Coupe's 4-bit display mode. The
change would also mean 4 times the
amount of display data for any
drawing, which would slow the
emulator down a bit. I also cut the
available memory from 24K in the
original version to 3K in the
released version. Part of that was
for software compatibility, but it
was mainly to give more space for the
Spectrum display & some look-up
tables. I should be able to provide
at least 16K by moving a few things
around, perhaps having the Spectrum
display in a different memory bank.
CF. You have given the source code
away, how would you feel about others
altering & maybe tweaking the
software?
SO. I'm quite happy for any or all of
it to be used, if they credit me
somewhere. That could mean using the
6502 core in a completely different
project, or submitting improvements
to the existing emulator.
CF. Do you have any other software;
we better say C= related in the
pipeline?
SO. Nothing currently, though new
projects do have a habit of springing
up from nowhere! There has been some
recent discussion about a SID board
for the Spectrum, for playing C64
tunes during Spectrum games. It's
certainly wacky enough for me to look
at getting involved if it takes off.
CF. Well whatever your motives I
think this is a major achievement & I
have to take my hat of to you well
done.
SO. Thank you for your interest & an
interesting interview!
..end..